package sk.uniza.fri.cerviix.client.graphics;

import org.lwjgl.opengl.GL11;

public class Font
{
	private Texture bitmap;
	
	public Font(Texture fontBitmap)
	{
		this.bitmap = fontBitmap;
	}
	
	public void drawText(String text)
	{		
		int width = 3;
		
		for (int i = 0; i < text.length(); i++)
		{
			char character = text.charAt(i);
			
			if (character == 32)
			{
				continue;
			}
			
			if (character > 57)
			{
				character -= 39;
			}
			
			character -= 48;
			
			float chunk = 1.0f / 36.0f;
			float start = chunk * character, end = chunk * (character + 1);
			
			GL11.glPushMatrix();
				GL11.glTranslatef(i * width, 0.0f, 0.0f);
			
				bitmap.bind();
				
				GL11.glBegin(GL11.GL_QUADS);
					GL11.glTexCoord2f(start, 0.0f);
					GL11.glVertex2f( 0.0f, 4.0f);
					
					GL11.glTexCoord2f(end, 0.0f);
					GL11.glVertex2f( 2.0f, 4.0f);
					
					GL11.glTexCoord2f(end, 1.0f);
					GL11.glVertex2f( 2.0f, 0.0f);
					
					GL11.glTexCoord2f(start, 1.0f);
					GL11.glVertex2f( 0.0f, 0.0f);
				GL11.glEnd();
				
				GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
			GL11.glPopMatrix();
		}
	}
}
